// pages/financial/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //获取userinfo
userinfo:'',
  /**
   * 页面的初始数据
   */
  ident:"",
    tableHeader: [
      {
        prop: 'awardName',
        width: 145,
        label:'',
      },
      // {
      //   prop: 'curMonthSpend',
      //   width: 145,
      //   label: '销量'
      // },
      // {
      //   prop: 'flag',
      //   width: 145,
      //   label: '月度业绩'
      // },
      {
        prop: 'dueMoney',
        width: 145,
        label: '预计积分'
      },
      {
        prop: 'realMoney',
        width: 145,
        label: '实得积分'
      }
    ],
    tableHeaders: [{
      prop: 'time',
      width: 225,
      label: '月度',
    },
    {
      prop: 'sale',
      width: 235,
      label: '达成分值'
    },
    {
      prop: 'flagStr',
      width: 265,
      label: '是否达标'
    }
  ],
    stripe: true,
    border: false,
    outBorder: true,
    userId:'',
    row: [
      {
          "id": 1,
          "status": '正常',
          "datetime": "落地费",
          "sign": '2000',
          "yue": '未达标',
          "work_hour": 80,
          "statusText":21212
      }, {
        "id": 2,
        "status": '正常',
        "datetime": "销量奖",
        "sign": '2000',
        "yue": '未达标',
        "work_hour": 80,
        "statusText":21212
    },{
      "id": 3,
      "status": '正常',
      "datetime": "共享奖",
      "sign": '2000',
      "yue": '未达标',
      "work_hour": 80,
      "statusText":21212
  },{
    "id": 4,
    "status": '正常',
    "datetime": "经理奖",
    "sign": '2000',
    "yue": '未达标',
    "work_hour": 80,
    "statusText":21212
},{
  "id": 5,
  "status": '正常',
  "datetime": "总监奖",
  "sign": '2000',
  "yue": '未达标',
  "work_hour": 80,
  "statusText":21212
}
    ],
    xjd:0,
    msg: '暂无数据',
    allmoney:0,
    daomoney:0,
    lev:0,
    showis:false,
    isyue:false,
    // awardList:[{"awardName":"销量奖","curMonthSpend":0.00,"flag":"未达标","dueMoney":0.00,"realMoney":0},{"awardName":"网体服务费","curMonthSpend":0.00,"dueMoney":0.00,"realMoney":0}],

  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //获取userinfo
this.data.userinfo = wx.getStorageSync('userinfo')
console.log(this.data.userinfo);
   this.data.tableHeader[0].label=wx.getStorageSync('loginuser').levelName
  //  this.data.lev=wx.getStorageSync('loginuser').level;
  this.setData({
    lev:wx.getStorageSync('loginuser').level,
    tableHeader:[
      {
        prop: 'awardName',
        width: 300,
        label:wx.getStorageSync('loginuser').levelName,
      },
      // {
      //   prop: 'curMonthSpend',
      //   width: 145,
      //   label: '销量'
      // },
      // {
      //   prop: 'flag',
      //   width: 145,
      //   label: '月度业绩'
      // },
      {
        prop: 'dueMoney',
        width: 200,
        label: '预计积分'
      },
      {
        prop: 'realMoney',
        width: 220,
        label: '实得积分'
      }
    ], 
   
   }) 
   console.log(this.data.lev);

    this.data.userId=wx.getStorageSync('userId')
   //获取真实数据渲染信息
wx.request({
  url: app.globalData.url+'/zkxj/user/getZDAward',
  data: {
    "userId": this.data.userId,
  },
  method: 'GET',
  header: {
   'content-type': 'application/json',
        'token':wx.getStorageSync('token')
  },
  success:(res)=>{
    
    console.log(res);
    if(res.data.code==0){
console.log(res);
      this.setData({ 
       row:res.data.data.awardList,
       xjd:res.data.data.xjd||0,
       allmoney:res.data.data.realTotalMoney,
       daomoney:res.data.data.curMonthMoney
      })
      
    //  var mon= this.data.row.map(item=>item.realMoney)
    // this.setData({
    //   allmoney:mon.reduce((allmoney,item)=>(allmoney+item),0)
    // })
    }
    
  }
  })
  //获取真实数据渲染信息
  wx.request({
    url: app.globalData.url + '/zkxj/user/sale/month/count',
    data: {
      "userId": this.data.userId,
    },
    method: 'GET',
    header: {
      'content-type': 'application/json',
      'token': wx.getStorageSync('token')
    },
    success: (res) => {
      console.log(res);
      if (res.data.code == 0) {
        this.setData({
          rows: res.data.data,
        })

        //  var mon= this.data.row.map(item=>item.realMoney)
        // this.setData({
        //   allmoney:mon.reduce((allmoney,item)=>(allmoney+item),0)
        // })
      }

    }
  })
  },
  hancheckyue(){
this.setData({
  isyue:false
})
var timestamp = Date.parse(new Date());
var date = new Date(timestamp);
//获取年份  
var Y =date.getFullYear();
//获取月份  
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
//获取当日日期 
var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); 
let timet=  Y +'-' + (M-1); 
if(this.data.isyue){
  wx.request({
    url: app.globalData.url+'/zkxj/user/getZDAward',
    data: {
      "userId": this.data.userId,
      "time":timet
    },
    method: 'GET',
    header: {
     'content-type': 'application/json',
          'token':wx.getStorageSync('token')
    },
    success:(res)=>{
      
      console.log(res);
      if(res.data.code==0){
  console.log(res);
        this.setData({ 
         row:res.data.data.awardList,
         xjd:res.data.data.xjd||0,
         allmoney:res.data.data.realTotalMoney,
         daomoney:res.data.data.curMonthMoney
        })
        
      //  var mon= this.data.row.map(item=>item.realMoney)
      // this.setData({
      //   allmoney:mon.reduce((allmoney,item)=>(allmoney+item),0)
      // })
      }
      
    }
    })
}else{
  wx.request({
    url: app.globalData.url+'/zkxj/user/getZDAward',
    data: {
      "userId": this.data.userId,
    },
    method: 'GET',
    header: {
     'content-type': 'application/json',
          'token':wx.getStorageSync('token')
    },
    success:(res)=>{
      console.log(res);
      if(res.data.code==0){
        this.setData({ 
         row:res.data.data.awardList,
         xjd:res.data.data.xjd||0,
         allmoney:res.data.data.realTotalMoney,
         daomoney:res.data.data.curMonthMoney
        })
      }
      
    }
    })
}
  },
  hancheckyues(){
    this.setData({
      isyue:true
    })
    var timestamp = Date.parse(new Date());
    var date = new Date(timestamp);
    //获取年份  
    var Y =date.getFullYear();
    //获取月份  
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    //获取当日日期 
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); 
    console.log(M);
    if(M<=10){
      let timet=  Y +'-'+'0'+(M-1); 
      if(this.data.isyue){
        wx.request({
          url: app.globalData.url+'/zkxj/user/getZDAward',
          data: {
            "userId":this.data.userId,
            "time":timet
          },
          method: 'GET',
          header: {
           'content-type': 'application/json',
                'token':wx.getStorageSync('token')
          },
          success:(res)=>{
            if(res.data.code==0){
              this.setData({ 
               row:res.data.data.awardList,
               xjd:res.data.data.xjd||0,
               allmoney:res.data.data.realTotalMoney,
               daomoney:res.data.data.curMonthMoney
              })
              
            //  var mon= this.data.row.map(item=>item.realMoney)
            // this.setData({
            //   allmoney:mon.reduce((allmoney,item)=>(allmoney+item),0)
            // })
            }
            
          }
          })
      }else{
        wx.request({
          url: app.globalData.url+'/zkxj/user/getZDAward',
          data: {
            "userId": this.data.userId,
          },
          method: 'GET',
          header: {
           'content-type': 'application/json',
                'token':wx.getStorageSync('token')
          },
          success:(res)=>{
            console.log(res);
            if(res.data.code==0){
              this.setData({ 
               row:res.data.data.awardList,
               xjd:res.data.data.xjd||0,
               allmoney:res.data.data.realTotalMoney,
               daomoney:res.data.data.curMonthMoney
              })
            }
            
          }
          })
      }
    }else{
      let timet=  Y +'-'+(M-1); 
      if(this.data.isyue){
        wx.request({
          url: app.globalData.url+'/zkxj/user/getZDAward',
          data: {
            "userId":this.data.userId,
            "time":timet
          },
          method: 'GET',
          header: {
           'content-type': 'application/json',
                'token':wx.getStorageSync('token')
          },
          success:(res)=>{
            if(res.data.code==0){
              this.setData({ 
               row:res.data.data.awardList,
               xjd:res.data.data.xjd||0,
               allmoney:res.data.data.realTotalMoney,
               daomoney:res.data.data.curMonthMoney
              })
              
            //  var mon= this.data.row.map(item=>item.realMoney)
            // this.setData({
            //   allmoney:mon.reduce((allmoney,item)=>(allmoney+item),0)
            // })
            }
            
          }
          })
      }else{
        wx.request({
          url: app.globalData.url+'/zkxj/user/getZDAward',
          data: {
            "userId": this.data.userId,
          },
          method: 'GET',
          header: {
           'content-type': 'application/json',
                'token':wx.getStorageSync('token')
          },
          success:(res)=>{
            console.log(res);
            if(res.data.code==0){
              this.setData({ 
               row:res.data.data.awardList,
               xjd:res.data.data.xjd||0,
               allmoney:res.data.data.realTotalMoney,
               daomoney:res.data.data.curMonthMoney
              })
            }
            
          }
          })
      }
    }
      },
  handlecheckshow(){
this.setData({
  showis:!this.data.showis
})
  },

  // * 点击表格一行
   
  onRowClick: function(e) {
    console.log('e: ', e)},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})